package com.atguigu.realtime.util;

import lombok.SneakyThrows;
import org.wltea.analyzer.core.IKSegmenter;
import org.wltea.analyzer.core.Lexeme;

import java.io.StringReader;
import java.util.HashSet;
import java.util.Set;

/**
 * @Author lizhenchao@atguigu.cn
 * @Date 2021/12/3 9:59
 */
public class IkAnalyzerUtil {
    @SneakyThrows
    public static Set<String> split(String word) {
        Set<String> keywords = new HashSet<>();
        // 如何把字符串转成字符输入流: Reader
        // 内存流
        StringReader reader = new StringReader(word);
        IKSegmenter seg = new IKSegmenter(reader, true);
        Lexeme next = seg.next();  // 我是中国人
        while (next != null){
            keywords.add(next.getLexemeText());
            next = seg.next();
        }
        return keywords;
    }
    
    public static void main(String[] args) {
        System.out.println(split("我是中国人"));
    }
}
/*
手机小米手机智能手机 ....
 */